package cn.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class StuDao {
  @Autowired DataSource dataSource;
  //显示stu表里所有数据
  public void query(){
    try (
      Connection connection = dataSource.getConnection();
      PreparedStatement preparedStatement = connection.prepareStatement("select * from stu");
      ResultSet resultSet = preparedStatement.executeQuery();){
      while (resultSet.next()){
        System.out.println(resultSet.getString("name"));
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
}
